#include <iostream>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

class Solution {
    vector<vector<int> > fgs;
    vector<int> X={1,-1,0,0};
    vector<int> Y={0,0,1,-1};
    int count;
    int kk;
public:
    int can(int i,int j){
        int ans=0;
        while(i){
            ans+=i%10;
            i/=10;
        }
        
        while(j){
            ans+=j%10;
            j/=10;
        }
        if(ans>kk){
            fgs[i][j]=1;
            return 0;
        }
        return 1;
    }
    void dfs(int id,int jd,int rows,int cols){
        if(id<0||id>=rows||jd<0||jd>=cols||fgs[id][jd]||!can(id,jd)){
            return;
        }
        fgs[id][jd]=1;
        count++;
        for(int i=0;i<4;i++){
            int new_i=id+X[i];
            int new_j=jd+Y[i];
            dfs(new_i,new_j,rows,cols);
        }

    }

    int movingCount(int threshold, int rows, int cols)
    {
        count=0;
        fgs=vector<vector<int> >(rows,vector<int>(cols,0));
        kk=threshold;
        dfs(0,0,rows,cols);
        return count;
    }
};

int main(){
    Solution s;
    cout << s.movingCount(1,2,2)<<endl;



    return 0;
}